package com.onpositive.mediawiki.deserializing;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;

import storage.v1.CategoryStorage;

import com.onpositive.data.IReadableObjectCollection;
import com.onpositive.data.diskstorage.StoredCollection;
import com.onpositive.data.serializer.readers.ObjectCollectionReader;
import com.onpositive.data.serializer.readers.RandomAccessFileAccess;

public abstract class SerializedStorage extends CategoryStorage {

	private String binaryPath ;
	
	public SerializedStorage( String binaryPath ) {
		super();
		
		this.binaryPath = binaryPath ;
		
		//String binaryPath = "C:\\wikistorage\\!serialized.dat" ;

		ObjectCollectionReader reader = new ObjectCollectionReader() ;
		RandomAccessFile rf ;
		try {
			rf = new RandomAccessFile( new File(binaryPath), "r" ) ;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return ;
		}
		IReadableObjectCollection<?>[] result = reader.getCollection( new RandomAccessFileAccess( rf ) ) ;
		
		StoredCollection col0 = (StoredCollection)result[0] ;
		
		CollectionDeserializer cDes = new CollectionDeserializer( col0, binaryPath ) ;
		
		this.setCategory( cDes.getCategory() ) ;		

	}

	public String getBinaryPath() {
		return binaryPath;
	}


	
	

}
